package com.an.blog.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.an.blog.admin.domain.bo.BlogCommentBo;
import com.an.blog.admin.domain.vo.BlogCommentVo;
import com.an.blog.service.IBlogCommentService;
import com.an.common.annotation.Log;
import com.an.common.core.controller.BaseController;
import com.an.common.core.domain.PageQuery;
import com.an.common.core.domain.R;
import com.an.common.core.page.TableDataInfo;
import com.an.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.Arrays;

/**
 * 博客评论
 *
 * @author Ann
 * @date 2023-05-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/blog/comment")
public class BlogCommentController extends BaseController {

    private final IBlogCommentService iBlogCommentService;

    /**
     * 查询博客评论列表
     */
    @SaCheckPermission("blog:comment:list")
    @GetMapping("/list")
    public TableDataInfo<BlogCommentVo> list(BlogCommentBo bo, PageQuery pageQuery) {
        return iBlogCommentService.queryPageList(bo, pageQuery);
    }


    /**
     * 删除博客评论
     *
     * @param commentIds 主键串
     */
    @SaCheckPermission("blog:comment:remove")
    @Log(title = "博客评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{commentIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] commentIds) {
        return toAjax(iBlogCommentService.deleteWithValidByIds(Arrays.asList(commentIds), true));
    }
}
